<?php

use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use common\helpers\Html;

$this->title = '编辑';
$this->params['breadcrumbs'][] = ['label' => '个人管理', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $this->title];
?>

<div class="row">
    <div class="col-lg-12">
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title">基本信息</h3>
            </div>
            <?php $form = ActiveForm::begin([
                'id'=>'form',
                'fieldConfig' => [
                    'template' => "<div class='col-sm-2 text-right'>{label}</div><div class='col-sm-10'>{input}{hint}{error}</div>",
                ]
            ]); ?>
            <div class="box-body">
                <?= $form->field($model, 'name')->textInput() ?>
                <?= $form->field($model, 'tel')->textInput() ?>
<!--                --><?//= $form->field($model, 'sex')->textInput() ?>
                <?= $form->field($model, 'sex')->radioList([1=>'男',2=>'女']) ?>
                <?= $form->field($model, 'img')->widget(\backend\widgets\cropper\Cropper::class, [
                    // 'theme' => 'default',
                    'config' => [
                        // 可设置自己的上传地址, 不设置则默认地址
                        // 'server' => '',
                    ],
                ]); ?>
                <?= $form->field($model, 'cla_id')->widget(Select2::class, [
                    'data' => $claList,
                    'options' => ['placeholder' => '请选择'],
                    'pluginOptions' => [
                        'allowClear' => true
                    ],
                ]);?>
                <div class="row">
                    <div class="col-lg-12">
                        <?= $form->field($model, 'hobby_id')->checkboxList($getHobby); ?>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-12">
                        <?= $form->field($model, 'mail')->textInput(); ?>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-12">
                        <?= $form->field($model, 'code')->textInput(); ?>
                    </div>
                </div>
            </div>
            <!-- /.box-body -->
            <div class="box-footer">
                <div class="col-sm-12 text-center">
                    <?=Html::button('点击获取验证码',['class'=>'btn btn-primary','id'=>'aa','style'=>"background-color:green"]);?>
                    <button class="btn btn-primary" type="submit" onclick="SendForm()" id="bb">保存</button>
                    <span class="btn btn-white" onclick="history.go(-1)">返回</span>
                </div>
            </div>
            <?php ActiveForm::end(); ?>
        </div>
    </div>
</div>
<script>
    $(function () {
        $('#aa').click(function () {
            var val = $("input[name='PersonForm[mail]']").val();
            var vals = $("input[name='Person[mail]']").val();
            $.ajax({
                type:'post',
                url:"sendmail",
                data:{
                    'val':val,
                    'vals':vals,
                },
                success:function (e) {
                    if(e.code==400){
                        alert(e.msg);
                        return;
                    }
                    if(e==1){
                        alert('发送成功');
                    }else{
                        alert('失败')
                    }
                }
            })
        });

    })
</script>
<script>
    var $form = $('#form');
    $form.on('beforeSubmit', function () {
        var data = $form.serialize();

        $.ajax({
            type: "post",
            url: "edit",
            dataType: "json",
            data: data,
            success: function (data) {
                if (parseInt(data.code) === 200) {
                    parent.location.reload();
                    window.location.reload();
                } else {
                    rfWarning(data.message);
                }
            }
        });

        return false; // 防止默认提交
    });
</script>